package com.youxin.jobcenter.service;
import java.math.BigDecimal;
import java.util.List;
import java.util.Map;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Service;

import com.youxin.busfoundation.Consts;
import com.youxin.busfoundation.bean.ResponseObject;
import com.youxin.busfoundation.enums.OrderPayStatusEnums;
import com.youxin.busfoundation.enums.PayTypeEnums;
import com.youxin.cpcenter.bean.RequestTradeQueryBean;
import com.youxin.cpcenter.dao.TbOrderInfoMapper;
import com.youxin.cpcenter.model.TbOrderInfo;
import com.youxin.cpcenter.service.TransactionService;
import com.youxin.cpcenter.service.impl.BaseServiceImpl;
import com.youxin.foundation.utils.JsonUtils;
import com.youxin.foundation.utils.StringUtils;


/**
 * 
 * @ClassName: AliPayService 
 * @Description: 支付宝订单交易状态查询 
 * @author yingde.cao
 * @date 2017年12月13日 上午10:04:59 
 *
 */
@Configuration
@Service("payStatusCheckService")
public class PayStatusCheckService extends BaseServiceImpl{

	@Autowired
	private TbOrderInfoMapper tbOrderInfoMapper;
	@Autowired
	private TransactionService transactionService;
	
	/**
	 * @Title: selectFailurePayOrderList 
	 * @Description: 查询没有支付状态订单
	 * @param 
	 * @return void
	 * @throws
	 */
	public void selectFailurePayOrderList() {
		TbOrderInfo orderInfo = new TbOrderInfo();
		List<TbOrderInfo> transFailedList = tbOrderInfoMapper.selectFailurePayOrderList(orderInfo);
		if(!transFailedList.isEmpty()){
			for (TbOrderInfo tbOrderInfo : transFailedList) {
				try {
					String orderSn = tbOrderInfo.getOrderSn();
					if(!StringUtils.isNullOrEmpty(orderSn)/* && !StringUtils.isNullOrEmpty(platformNo)*/){
						logger.warn("支付接口查询订单参数：orderSn:"+orderSn);
						TbOrderInfo model = new TbOrderInfo();
						if(tbOrderInfo.getPayType().equals(PayTypeEnums.WX.getIndex())) {
							model = transactionService.queryWx(orderSn);
						}else if(tbOrderInfo.getPayType().equals(PayTypeEnums.ZFB.getIndex())) {
							model = transactionService.queryAlipay(orderSn);
						}
						if(model.getPayStatus().intValue()==OrderPayStatusEnums.WaitPay.getValue())
						{
							continue;
						}
						transactionService.procesNotifyTransaction(model);
					}
				} catch (Exception e) {
					logger.error("selectFailurePayOrderList:",e);
				}
				
			}
		}
	}
	
}
